package cn.edu.neusoft.yyd208.foodorder.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import cn.edu.neusoft.yyd208.foodorder.R;
import cn.edu.neusoft.yyd208.foodorder.bean.RegisterBean;
import cn.edu.neusoft.yyd208.foodorder.listener.TListener;
import cn.edu.neusoft.yyd208.foodorder.model.ModifyModel;

public class ModifyActivity extends BaseActivity {
    EditText et_mdusername,et_mduserpass,et_mdtel,et_mdaddress;
    Button commit;
    String userid,username,userpass,tel,address;
    TListener<RegisterBean> modifyListener=new TListener<RegisterBean>() {
        @Override
        public void onResponse(RegisterBean registerBean) {
            if(registerBean.getSuccess().equals("1")){
                showToast("修改成功");
                finish();
            }
            else {
                showToast("修改失败");
            }

        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    void initView() {
        setLayout_file(R.layout.activity_modify);
        et_mdusername=(EditText)findViewById(R.id.et_mdusername);
        et_mduserpass=(EditText)findViewById(R.id.et_mduserpass);
        et_mdtel=(EditText)findViewById(R.id.et_mdtel);
        et_mdaddress=(EditText)findViewById(R.id.et_mdaddress);
        commit=(Button)findViewById(R.id.commit);
        SharedPreferences sp=getSharedPreferences("userInfo",MODE_PRIVATE);
        String username2=sp.getString("username","");
        et_mdusername.setText(username2);
        String userpass2=sp.getString("userpass","");
        et_mduserpass.setText(userpass2);
        String tel2=sp.getString("tel","");
        et_mdtel.setText(tel2);
        String address2=sp.getString("address","");
        et_mdaddress.setText(address2);
    }

    @Override
    void initEvent() {
        commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getIntent();
                String userid=intent.getStringExtra("userid");
                username=et_mdusername.getText().toString();
                userpass=et_mduserpass.getText().toString();
                tel=et_mdtel.getText().toString();
                address=et_mdaddress.getText().toString();
                ModifyModel modifyModel=new ModifyModel();
                modifyModel.getRegisterMessage(userid,username,userpass,tel,address,modifyListener);
            }
        });

    }

    @Override
    void initData() {

    }


}
